package com.zw.pm.module.board.dailyoutput;


import com.zw.pm.gen.entity.Factory;
import com.zw.pm.gen.entity.TaskDaily;
import com.zw.pm.gen.entity.TaskDailyExample;
import com.zw.pm.gen.mapper.TaskDailyMapper;
import com.zw.pm.module.board.single.TaskDao;
import com.zw.pm.module.config.factory.FactoryDao;
import com.zw.pm.module.project.build.ProjectDao;
import com.zw.pm.module.project.build.ProjectModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

import static com.zw.pm.constant.Constant.STATUS_NORMAL;

/**
 * @Description: 日产量 服务层
 * @Author: China.sgl
 * @Date: 2019/9/16 09:11
 */
@Service
public class DailyOutputService {

    @Autowired
    private ProjectDao projectDao;
    @Autowired
    private FactoryDao factoryDao;
    @Autowired
    private TaskDailyMapper taskDailyMapper;
    @Autowired
    private TaskDao taskDao;
    @Autowired
    private DailyOutputDao dailyOutputDao;


    /**
     * 根据条件查询项目
     *
     * @param projectModel 查询条件
     * @return 项目列表数据
     */
    public List<ProjectModel> findProjectDaily(ProjectModel projectModel) {
        return projectDao.findProjectDaily(projectModel);
    }


    /**
     * 保存日报表
     *
     * @param taskDaily taskDaily
     * @return 行数
     */
    public int saveTaskDaily(TaskDaily taskDaily) {
        taskDaily.setStatus(STATUS_NORMAL);
        taskDaily.setCreateTime(new Date());
        taskDaily.setTaskId(taskDao.findTaskIdByProjectIdAndFactoryId(taskDaily.getProjectId(), taskDaily.getFactoryId()));
        return taskDailyMapper.insert(taskDaily);
    }

    /**
     * 查询所有生产厂
     *
     * @return list
     */
    public List<Factory> findFactories() {
        return factoryDao.findIdNotIn(new Integer[]{4});
    }

    /**
     * 查询任务下达工厂
     *
     * @param id 项目ID
     * @return list
     */
    public List<Factory> findTaskFactory(Integer id) {
        return factoryDao.findTaskFactory(id);
    }

    /**
     * 查询项目日报表
     *
     * @param dailyOutputModel dailyOutputModel
     * @return list
     */
    public List<DailyOutputModel> findProjectDailyList(DailyOutputModel dailyOutputModel) {
        return dailyOutputDao.findProjectDailyList(dailyOutputModel);
    }

    /**
     * 删除
     *
     * @param taskDaily taskDaily
     * @return 影响行数
     */
    public int delTaskDaily(TaskDaily taskDaily) {
        return taskDailyMapper.updateByPrimaryKeySelective(taskDaily);
    }

    /**
     * 根据ID查询
     *
     * @param id id
     * @return TaskDaily
     */
    public DailyOutputModel findTaskDaily(Integer id) {
        return dailyOutputDao.findTaskDaily(id);
    }

    /**
     * 修改
     *
     * @param taskDaily taskDaily
     * @return 影响行数
     */
    public int updateTaskDaily(TaskDaily taskDaily) {
        return taskDailyMapper.updateByPrimaryKeySelective(taskDaily);
    }

}
